# TODO: write here Printer = pkg0.pkg1.Printer & move class Printer there

def splitForParagraphs(text):
	paragraphs = text.split("\n\n")
	lastParagraphIsCompleted = text.endswith("\n\n")
	if lastParagraphIsCompleted:
		return paragraphs, ""
	else:
		lastPar = paragraphs[len(paragraphs) - 1]
		paragraphs = paragraphs[:-1]
		return paragraphs, lastPar
	
class Paragraph:
	def __init__(self, paragraphText):
		self.__paragraphText = paragraphText
	
	def __str__(self):
		return "Prgrph[" + self.__paragraphText + "]"
	
class PrinterState:
	def __init__(self):
		self.__currentParagraph = ""
	
	def getCurrentParagraph(self):
		return self.__currentParagraph
	
	def setCurrentParagraph(self, currentParagraph):
		self.__currentParagraph = currentParagraph
	
class Document:
	def __init__(self):
		self.__documentElements = []
	
	def appendElement(self, element):
#		assert isinstance(element, IDoculentElement)
		self.__documentElements.append(element)
	
	def getElements(self):
		return self.__documentElements

class Printer:
	def __init__(self):
		self.__headerText = None
		self.__state = PrinterState()
		self.__doc = Document()

	def text(self, text):
		curPar = self.__state.getCurrentParagraph()
		text = curPar + text
		paragraphs, curPar = splitForParagraphs(text)
		self.__state.setCurrentParagraph(curPar)
		for paragraphText in paragraphs:
			if len(paragraphText) > 0:
				self.__doc.appendElement(Paragraph(paragraphText))

	def header(self, headerText):
		self.__headerText = headerText

	def nextParagraph(self):
		pass

	def finish(self):
		pass
